package cate.game.activity.rank;

import cate.game.activity.base.core.ActivityGlobalData;
import easy.java.dev.note.NoteField;

import java.util.HashMap;
import java.util.Map;

public class SingleRankGlobalData extends ActivityGlobalData {
    @NoteField("额外条件")
    public Map<String, Long> extraRecords;

    @Override
    public void initialize() {
        if (extraRecords == null) {
            this.extraRecords = new HashMap<>();
        }
    }

    @Override
    public void clear() {
        extraRecords.clear();
    }

    public synchronized void updateExtraRecords(String roleUid, long value, boolean add) {
        long v = value;
        if (add) {
            v += extraRecords.getOrDefault(roleUid, 0L);
        }
        extraRecords.put(roleUid, v);
    }

    public synchronized long getExtraRecords(String roleUid) {
        return extraRecords.getOrDefault(roleUid, 0L);
    }
}
